<?php

/**
 * 
 **/
class PasswordModificationForm extends sfForm
{
  public function configure()
  {
    $widget = new sfWidgetFormInputPassword(array(), array(
      'maxlength' => 15
    ));
    $this->setWidgets(array(
      'old_password' => $widget,
      'password' => $widget,
      'password_confirm' => $widget
    ));
    $validator = new sfValidatorString(array(
      'min_length' => 6,
      'max_length' => 15
    ), array(
      'required' => '必填',
      'min_length' => '至少6个字符',
      'max_length' => '至多15个字符'
    ));
    $this->setValidators(array(
      'old_password' => $validator,
      'password' => $validator,
      'password_confirm' => $validator
    ));

    $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
      new sfValidatorSchemaCompare('password', '==', 'password_confirm', array(), array(
        'invalid' => '两次密码输入不匹配'
      )),
      new PasswordValidator()
    )));

    $this->widgetSchema->setNameFormat('password[%s]');
  }
}
